package com.cloudkinto.controller.product;

import com.cloudkinto.base.BaseController;
import com.cloudkinto.common.annotations.UserSessionRequired;
import com.cloudkinto.service.product.ProductBarCodeService;
import com.cloudkinto.service.product.vo.BarCodePrintReq;
import com.cloudkinto.service.product.vo.ProductInfoDetailRes;
import com.itextpdf.text.DocumentException;
import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author zhujiale
 * @description
 * @date 2022/11/15
 */
@RestController
@Api(tags = "打印条形码模块")
@RequestMapping("/api/barCode")
public class ProductBarCodeController extends BaseController {
    @Autowired
    private ProductBarCodeService service;

    @UserSessionRequired
    @GetMapping("/pageInit")
    @ApiOperation(value = "操作类型初始化", notes = "操作类型初始化")
    public Object operatingTypeInit() {
        return service.operatingTypeInit();
    }

    @UserSessionRequired
    @GetMapping("detail/{id}")
    @ApiOperation(value = "根据id获取商品信息", notes = "根据id获取商品信息")
    public Object getDetail(@PathVariable("id") Long id) {
        return service.getDetail(id);
    }

    @PostMapping("/BarCodePrint")
    @UserSessionRequired
    @ApiOperation(value = "生成条形码pdf", notes = "生成条形码pdf")
    @ApiResponses(@ApiResponse(code = 200, message = "", response = ProductInfoDetailRes.class))
    public Object barCodePrint(@RequestBody @Validated BarCodePrintReq req) throws IOException, DocumentException, TemplateException {
        return service.barCodePrint(req,getCurrentUserId());
    }

}
